package com.zrkizzy.seckill.controller.common;

import com.zrkizzy.seckill.dto.LoginDTO;
import com.zrkizzy.seckill.service.core.IUserService;
import com.zrkizzy.seckill.vo.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 登录前端控制器
 *
 * @author zhangrongkang
 * @since 2023/3/20
 */
@Controller
@RequestMapping("/login")
@Slf4j
public class LoginController {

    @Autowired
    private IUserService userService;

    /**
     * 跳转到登录页
     *
     * @return 登录页
     */
    @RequestMapping("/toLogin")
    public String toLogin() {
        return "web/system/login";
    }

    @PostMapping("/doLogin")
    @ResponseBody
    public Result doLogin(@Validated LoginDTO loginDTO, HttpServletRequest request, HttpServletResponse response) {
        return userService.doLogin(loginDTO, request, response);
    }
}
